﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DataAccess.Object;

namespace DataAccess
{
    public class DonHangDAO
    {
        DataAccess _conn = new DataAccess();
        public DataTable DS_DON_HANG()
        {
            return _conn.ExecuteDataTable("DS_DON_HANG");
        }
        public DataTable LayParam(string id)
        {
            SqlParameter[] pram = new SqlParameter[1];
            pram[0] = new SqlParameter("@maparam", SqlDbType.NVarChar);
            pram[0].Value = id;
            return _conn.ExecuteDataTable("LayPram", pram);
            
        }
        public void themDonHang(DonHangOB dh)
        {

            SqlParameter[] pram = new SqlParameter[23];


            pram[0] = new SqlParameter("@ma_hd", SqlDbType.NVarChar);
            pram[0].Value = dh.ma_dh;
            pram[1] = new SqlParameter("@ma_kh", SqlDbType.NVarChar);
            pram[1].Value = dh.ma_kh;
            pram[2] = new SqlParameter("@ten_kh", SqlDbType.NVarChar);
            pram[2].Value = dh.ten_kh;
            pram[3] = new SqlParameter("@sdt_kh", SqlDbType.NVarChar);
            pram[3].Value = dh.sdt_kh;
            pram[4] = new SqlParameter("@diachi_kh", SqlDbType.NVarChar);
            pram[4].Value = dh.diachi_kh;
            pram[5] = new SqlParameter("@ten_nh", SqlDbType.NVarChar);
            pram[5].Value = dh.ten_nh;
            pram[6] = new SqlParameter("@sdt_nh", SqlDbType.NVarChar);
            pram[6].Value = dh.sdt_nh;
            pram[7] = new SqlParameter("@diachi_nh", SqlDbType.NVarChar);
            pram[7].Value = dh.diachi_nh;
            pram[8] = new SqlParameter("@nguoilap_hd", SqlDbType.Int);
            pram[8].Value = dh.nguoilap_hd;
            pram[9] = new SqlParameter("@nhanvien_gh", SqlDbType.Int);
            pram[9].Value = dh.nhanvien_gh;
            pram[10] = new SqlParameter("@ngay_dh", SqlDbType.DateTime);
            pram[10].Value = dh.ngay_dh;
            pram[11] = new SqlParameter("@ngay_gh", SqlDbType.Int);
            pram[11].Value = dh.ngay_gh;
            pram[12] = new SqlParameter("@tinhtrang_gh", SqlDbType.NVarChar);
            pram[12].Value = dh.tinhtrang_gh;
            pram[13] = new SqlParameter("@tinhtrang_tt", SqlDbType.NVarChar);
            pram[13].Value = dh.tinhtrang_tt;
            pram[14] = new SqlParameter("@kieu_cp", SqlDbType.NVarChar);
            pram[14].Value = dh.kieu_cp;
            pram[15] = new SqlParameter("@chiphi_cp", SqlDbType.NVarChar);
            pram[15].Value = dh.chiphi_cp;
            pram[16] = new SqlParameter("@thoigian_cb", SqlDbType.Int);
            pram[16].Value = dh.thoigian_cb;
            pram[17] = new SqlParameter("@ghichu_hd", SqlDbType.NVarChar);
            pram[17].Value = dh.ghichu_hd;
            pram[18] = new SqlParameter("@tong_cp", SqlDbType.Int);
            pram[18].Value = dh.tong_cp;
            pram[19] = new SqlParameter("@xacnhan", SqlDbType.NVarChar);
            pram[19].Value = dh.xacnhan;
            pram[20] = new SqlParameter("@tinh_kh", SqlDbType.NVarChar);
            pram[20].Value = dh.tinh_kh;
            pram[21] = new SqlParameter("@tinh_nn", SqlDbType.NVarChar);
            pram[21].Value = dh.tinh_nn;
            pram[22] = new SqlParameter("@ngay_gh_datetime", SqlDbType.DateTime);
            pram[22].Value = dh.ngay_gh_datetime;
            
            _conn.ExecuteNonQuery("ThemDonHang", pram);
          
        }

        public void suaDonHang(DonHangOB dh)
        {
            SqlParameter[] pram = new SqlParameter[23];
            pram[0] = new SqlParameter("@ma_hd", SqlDbType.NVarChar);
            pram[0].Value = dh.ma_dh;
            pram[1] = new SqlParameter("@ma_kh", SqlDbType.NVarChar);
            pram[1].Value = dh.ma_kh;
            pram[2] = new SqlParameter("@ten_kh", SqlDbType.NVarChar);
            pram[2].Value = dh.ten_kh;
            pram[3] = new SqlParameter("@sdt_kh", SqlDbType.NVarChar);
            pram[3].Value = dh.sdt_kh;
            pram[4] = new SqlParameter("@diachi_kh", SqlDbType.NVarChar);
            pram[4].Value = dh.diachi_kh;
            pram[5] = new SqlParameter("@ten_nh", SqlDbType.NVarChar);
            pram[5].Value = dh.ten_nh;
            pram[6] = new SqlParameter("@sdt_nh", SqlDbType.NVarChar);
            pram[6].Value = dh.sdt_nh;
            pram[7] = new SqlParameter("@diachi_nh", SqlDbType.NVarChar);
            pram[7].Value = dh.diachi_nh;
            pram[8] = new SqlParameter("@nguoilap_hd", SqlDbType.Int);
            pram[8].Value = dh.nguoilap_hd;
            pram[9] = new SqlParameter("@nhanvien_gh", SqlDbType.Int);
            pram[9].Value = dh.nhanvien_gh;
            pram[10] = new SqlParameter("@ngay_dh", SqlDbType.DateTime);
            pram[10].Value = dh.ngay_dh;
            pram[11] = new SqlParameter("@ngay_gh", SqlDbType.Int);
            pram[11].Value = dh.ngay_gh;
            pram[12] = new SqlParameter("@tinhtrang_gh", SqlDbType.NVarChar);
            pram[12].Value = dh.tinhtrang_gh;
            pram[13] = new SqlParameter("@tinhtrang_tt", SqlDbType.NVarChar);
            pram[13].Value = dh.tinhtrang_tt;
            pram[14] = new SqlParameter("@kieu_cp", SqlDbType.NVarChar);
            pram[14].Value = dh.kieu_cp;
            pram[15] = new SqlParameter("@chiphi_cp", SqlDbType.NVarChar);
            pram[15].Value = dh.chiphi_cp;
            pram[16] = new SqlParameter("@thoigian_cb", SqlDbType.Int);
            pram[16].Value = dh.thoigian_cb;
            pram[17] = new SqlParameter("@ghichu_hd", SqlDbType.NVarChar);
            pram[17].Value = dh.ghichu_hd;
            pram[18] = new SqlParameter("@tong_cp", SqlDbType.Int);
            pram[18].Value = dh.tong_cp;
            pram[19] = new SqlParameter("@xacnhan", SqlDbType.NVarChar);
            pram[19].Value = dh.xacnhan;
            pram[20] = new SqlParameter("@tinh_kh", SqlDbType.NVarChar);
            pram[20].Value = dh.tinh_kh;
            pram[21] = new SqlParameter("@tinh_nn", SqlDbType.NVarChar);
            pram[21].Value = dh.tinh_nn;
            pram[22] = new SqlParameter("@ngay_gh_datetime", SqlDbType.DateTime);
            pram[22].Value = dh.ngay_gh_datetime;
            _conn.ExecuteNonQuery("SuaDonHang", pram);
        }

        public void themDH_SP(DH_SPOB dh_sp)
        {
            SqlParameter[] pram = new SqlParameter[3];
            pram[0] = new SqlParameter("@ma_hd", SqlDbType.NVarChar);
            pram[0].Value = dh_sp.ma_hd;
            pram[1] = new SqlParameter("@ma_sp", SqlDbType.NVarChar);
            pram[1].Value = dh_sp.ma_sp;
            pram[2] = new SqlParameter("@soluong", SqlDbType.Int);
            pram[2].Value = dh_sp.soluong;
            _conn.ExecuteNonQuery("ThemDH_SP", pram);
        }

        public DataTable DonHang_By_Id(string id)
        {
            SqlParameter[] pram = new SqlParameter[1];
            pram[0] = new SqlParameter("@ma_hd", SqlDbType.NVarChar);
            pram[0].Value = id;
            return _conn.ExecuteDataTable("Donhang_By_id",pram);
        }
        public void xoaDH_SP(string id)
        {
            SqlParameter[] pram = new SqlParameter[1];
            pram[0] = new SqlParameter("@ma_hd", SqlDbType.NVarChar);
            pram[0].Value = id;
            _conn.ExecuteNonQuery("XoaDH_SP",pram);
        }
        public void suaDH_SP(DH_SPOB dh_sp)
        {
            SqlParameter[] pram = new SqlParameter[3];
            pram[0] = new SqlParameter("@ma_hd", SqlDbType.NVarChar);
            pram[0].Value = dh_sp.ma_hd;
            pram[1] = new SqlParameter("@ma_sp", SqlDbType.NVarChar);
            pram[1].Value = dh_sp.ma_sp;
            pram[2] = new SqlParameter("@soluong", SqlDbType.Int);
            pram[2].Value = dh_sp.soluong;
            _conn.ExecuteNonQuery("SuaDH_SP", pram);
        }
        public DataTable timKiem(string where)
        {
            SqlParameter[] pram = new SqlParameter[1];
            pram[0] = new SqlParameter("@whereCondition", SqlDbType.NVarChar);
            pram[0].Value = where;
            return _conn.ExecuteDataTable("timKiem", pram);

        }
        public void xoaDH(string id)
        {
            SqlParameter[] pram = new SqlParameter[1];
            pram[0] = new SqlParameter("@ma_dh", SqlDbType.NVarChar);
            pram[0].Value = id;
            _conn.ExecuteNonQuery("xoaDH", pram);
        }
    }
}
